package ve.lm.hrms_cy.Utils;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.util.Config;
import org.springframework.stereotype.Component;

import java.awt.image.BufferedImage;
import java.util.Properties;

@Component
public class CaptchaUtil {

    private static Producer captchaProducer;

    static {
        Properties props = new Properties();
        props.put("kaptcha.image.width", "160");
        props.put("kaptcha.image.height", "60");
        props.put("kaptcha.textproducer.char.length", "5");
        props.put("kaptcha.textproducer.char.string", "abcde2345678gfynmnpwx");
        Config config = new Config(props);
        captchaProducer = config.getProducerImpl();
    }

    public static String generateText() {
        return captchaProducer.createText();
    }

    public static BufferedImage generateImage(String text) {
        return captchaProducer.createImage(text);
    }
}

